package com.nut.exception;

import com.nut.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一拦截异常
 */
@RestControllerAdvice
@Slf4j
public class GlobalDefaultExceptionHandler {

    /**
     * 主动throw的异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(ServiceException.class)
    @ResponseStatus(value = HttpStatus.OK)
    public Result<?> handleUnProcessableServiceException(ServiceException e) {
        return Result.fail(e.getMessage());
    }

}
